using System;
using System.Data;
using System.Configuration;
using System.Web;	 
using System.Drawing;   

namespace Possan.Graphics.Filters
{						  
	public class AddBorder : IBaseFilter
	{
		public int Left;
		public int Top;
		public int Right;
		public int Bottom;
		public string Color;

		public string ParameterDefinition
		{
			get
			{
				     return null;
			}
		}

		public AddBorder()
		{
			Left = 0;
			Top = 0;
			Right = 0;
			Bottom = 0;
			Color = "#ffffff";
		}

		public Bitmap Filter(Bitmap bitmap)
		{
			int w = bitmap.Width;
			int h = bitmap.Height;

			int nw = w + Left + Right;
			int nh = h + Top + Bottom;

			Bitmap bmp2 = new Bitmap(nw, nh);
			bmp2.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
			System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(bmp2);

			SolidBrush br = new SolidBrush(Utilities.ParseHtmlColor(Color));

			if (Left > 0)
			{
				g2.FillRectangle(br, new Rectangle(0, 0, Left, nh));
			}

			if (Right > 0)
			{
				g2.FillRectangle(br, new Rectangle(nw - Right, 0, Right, nh));
			}

			if (Top > 0)
			{
				g2.FillRectangle(br, new Rectangle(0, 0, nw, Top));
			}

			if (Bottom > 0)
			{
				g2.FillRectangle(br, new Rectangle(0, nh - Bottom, nw, Bottom));
			}

			g2.DrawImage(bitmap, Left, Top);

			     return bmp2;
		}

		public void Dispose()
		{
		}
	}
}





